<!-- 商家 -->
<template>
	<view class="app">
		<u-navbar title="" @rightClick="rightClick" :autoBack="true">
		</u-navbar>

		<view class="page-wrap">
			<scroll-list ref="list" :option="option" @load="load" @refresh="refresh">
				<view class="main" style="display: flex;">
					<view class="">
						<image :src="shopName.iconUrl" mode="" style="width: 90rpx;height: 90rpx;border-radius: 18rpx;">
						</image>
					</view>
					<view class="" style="margin-left: 18rpx;margin-bottom: 18rpx;">
						<text>{{shopName.name}}\n</text>
						<text style="font-size: .8rem;">月售{{shopName.monthSales}}件</text>
					</view>
				</view>
				<view class="list-item" v-for="(item, index) in shopInfo" :key="index" @click="handleTest(item)">
					<view class="info">
						<view class="info-item" style="display: flex;margin: 18rpx 0;">
							<image :src="item.img" mode="" style="width: 180rpx;height: 180rpx;border-radius: 18rpx;">
							</image>
							<view class=""
								style="width: 66%;margin-left: 18rpx;display: flex;flex-direction: column;justify-content: space-between;">
								<text
									style="overflow: hidden;text-overflow: ellipsis;-webkit-line-clamp: 2;display: -webkit-box;-webkit-box-orient: vertical;font-size: .9rem;">{{item.title}}</text>
								<view class="">
									<text v-for="coupons in item.coupons"
										style="color: #E70012;font-size: .65rem;margin: 0 6rpx;border-radius: 24rpx;border: 1px solid #E70012;padding: 2rpx 10rpx;">{{coupons}}</text>
								</view>
								<view class=""
									style="display: flex;justify-content: space-between;align-items: center;">
									<text
										style="color: #E70012;font-weight: bold;font-size: 1rem;">￥{{item.price}}</text>
									<text style="color: #888;font-size: .8rem;">销量{{item.sales}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</scroll-list>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				option: {
					size: 5,
					auto: true
				},
				shopId: "",
				shopName: Object,
				index: 1,
				shopInfo: []
			};
		},
		onLoad() {
			let routes = getCurrentPages()
			this.shopId = routes[routes.length - 1].options.shopId
			uni.request({
				url: "https://app-gw.juaiyouxuan.com/api-bff/openapi/v1/Shop/info?shopId=" + this.shopId,
				success: (res) => {
					this.shopName = res.data.data
				}
			})
		},
		methods: {
			load(paging) {
				setTimeout(() => {
					uni.request({
						url: "https://app-gw.juaiyouxuan.com/api-bff/openapi/product/shop-products?shopId=" +
							this.shopId + "&Title=&OrderBy=1&PageIndex=" + this.index + "&PageSize=10",
						success: (res) => {
							this.shopInfo = [...this.shopInfo, ...res.data.data.list]
							this.$refs.list.loadSuccess({
									list: this.shopInfo,
									total: 50
								}),
								this.index++
						}
					})
				})
			},
			refresh(paging) {
				this.$refs.list.refreshSuccess({
					list: this.shopInfo,
					total: 50
				})
			},
			handleTest(item) {
				console.log(item.productId);
				uni.navigateTo({
					url: "/pages/street/shopInfo/shopInfo?pid=" + item.productId
				})
			}
		}
	}
</script>

<style lang="less">
	.app {
		background-color: var(--bgcolor);
		padding: 18rpx;
	}

	.page-wrap {
		margin-top: 100rpx;
	}
</style>